package jt.com.jt809.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import jt.com.jt809.util.ByteArrayUtil;

/**
 * 客户端发送信息 编码
 *
 * @Author OuJiaJun
 * @Date 2024/4/24 14:57
 */
public class JT809TcpClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("channelActive..........");
        ctx.channel().write(ByteArrayUtil.hexStr2Bytes(
                "5B0000005A0000011812000001E2400100010000000000C1C9434437313635000000000000000000000000000212020000002400090707E31234230736F0DE026ECFEF00000000000184E9010C000E000C00030000000012725D"
        ));
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("channelRead.........." + ByteArrayUtil.bytes2HexStr((byte[])msg));
        super.channelRead(ctx,msg);
    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("exceptionCaught..........");
        cause.printStackTrace();
        ctx.close();
    }
}
